package cc.shimeng.fucloud.tools;

import cc.shimeng.fucloud.entity.Grade;
import cc.shimeng.fucloud.repository.GradeRepository;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

@Component
public class GradeTool {

    @Autowired
    private GradeRepository gradeRepository;

    @Tool(description = "获取所有年级信息", name = "gradeGetAll")
    public List<Grade> getAll() {
        return gradeRepository.findAll();
    }

    @Tool(description = "获取年级信息", name = "gradeGet")
    public Optional<Grade> get(@ToolParam(description = "年级ID") Integer id) {
        return gradeRepository.findById(id);
    }

    @Tool(description = "创建年级信息", name = "gradeSave")
    public Grade save(Grade grade) {
        return gradeRepository.save(grade);
    }

    @Tool(description = "删除年级信息", name = "gradeDelete")
    public void delete(@ToolParam(description = "年级ID") Integer id) {
        gradeRepository.deleteById(id);
    }
}